package br.gov.ibama.client.visao.nota;

import java.util.ArrayList;
import java.util.List;

import br.gov.ibama.client.AuthService;
import br.gov.ibama.client.AuthServiceAsync;
import br.gov.ibama.client.componentes.BasisComponentes;
import br.gov.ibama.client.constantes.ConstantesDS;
import br.gov.ibama.client.constantes.ConstantesFields;
import br.gov.ibama.client.visao.VisaoPopup;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.HiddenItem;

public class VisaoPopupFormularioNota extends VisaoPopup{

	public static final AuthServiceAsync authService = GWT
			.create(AuthService.class);
	
	public VisaoPopupFormularioNota(String title) {
		super (title);
	}

	protected List<ImgButton> getBotoes (){
		List<ImgButton> listaBotoes = new ArrayList<ImgButton>();
		listaBotoes.add(getBotaoSalvar());
		listaBotoes.add(getBotaoCancelar());
		return listaBotoes;
	}
	
	private ImgButton getBotaoSalvar(){
		ImgButton Salvar = BasisComponentes.criaImgButton("Salvar", "salvar_32x32.png");
		Salvar.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				SC.say("Frequência registrada com sucesso!");
				destroy();
			}
		});
		return Salvar;
	}
		
	private ImgButton getBotaoCancelar(){
		ImgButton Cancelar = BasisComponentes.criaImgButton("Cancelar", "cancelar_32x32.png");
		Cancelar.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				destroy();
				
			}
		});
		return Cancelar;
	}
	
	public void criaFormulario(){
		preparaFormulario(ConstantesDS.DS_NOTA, getListaCamposFormulario());
	}
	
	public FormItem[] getListaCamposFormulario(){
		return getCamposFormulario().toArray(new FormItem[getCamposFormulario().size()]);
	}
	
	private List<FormItem> getCamposFormulario(){
	
		List<FormItem> listaCampos = new ArrayList<FormItem>();
		
		HiddenItem codigoFrequencia = new  HiddenItem(ConstantesFields.FIELD_NOTA_ID);
		codigoFrequencia.setCanEdit(false);
		listaCampos.add(codigoFrequencia);
		
		return listaCampos;		
	}
	
}
